package com.leo.component;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.component.Component;
import com.almasb.fxgl.texture.AnimatedTexture;
import com.almasb.fxgl.texture.AnimationChannel;
import javafx.util.Duration;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-18  19:59
 * @Description: TODO
 */
public class FruitComponent extends Component {

    AnimatedTexture at;

    @Override
    public void onAdded() {
        at = new AnimatedTexture(new AnimationChannel(FXGL.image("selected.png", 882 / 2, 149 / 2), Duration.seconds(.5), 6));
        at.setTranslateX(entity.getWidth() / 2 - at.getWidth() / 2 / 6);
        at.setTranslateY(entity.getHeight() / 2 - at.getHeight() / 2);
    }

    public void select(boolean isSelect) {
        if (isSelect) {
            at.loop();
            entity.getViewComponent().addChild(at);
        } else {
            at.stop();
            entity.getViewComponent().removeChild(at);
        }
    }
}
